package com.longma.server.pojo;

import com.alibaba.fastjson.JSON;
import com.longma.server.constant.enums.ResponseCode;
import lombok.NoArgsConstructor;


/**
 * @author HIBO
 * @Description 返回体构造工具
 */
@NoArgsConstructor
public class UserResponseEntity<T> extends ResponseMessage<T> {

    /**
     * 构造函数
     * @param responseCode
     * @param data
     */
    public UserResponseEntity(ResponseCode responseCode, T data) {
        super(responseCode, data);
    }

    public UserResponseEntity(int code, String msg, T data) {
        super(code, msg, data);
    }


    /**
     * 成功
     * @param <T>
     * @return
     */
    public static <T> UserResponseEntity<T> success(){
        return success(null);
    }

    public static <T> UserResponseEntity<T> success(T data){
        return new UserResponseEntity<>(ResponseCode.SUCCESS,data);
    }

    public static <T> UserResponseEntity<T> success(String msg, T data){
        return new UserResponseEntity<>(200, msg,data);
    }

    public static <T> UserResponseEntity<T> fail(String msg, T data){
        return new UserResponseEntity<>(500, msg,data);
    }

    /**
     * 失败
     * @param <T>
     * @return
     */
    public static <T> UserResponseEntity<T> fail(){
        return fail(null);
    }
    public static <T> UserResponseEntity<T> fail(ResponseCode responseCode){
        return new UserResponseEntity<>(responseCode,null);
    }
    public static <T> UserResponseEntity<T> fail(T data){
        return new UserResponseEntity<>(ResponseCode.FAIL,data);
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }
}
